<?php
	//function crop image theo cac chuan x345 x200 original, hien tai chi danh cho file jpg
	function cropProductImg($imgSrc,$idSrcImg) {
		//getting the image dimensions
		list($width, $height) = getimagesize($imgSrc);

		//saving the image into memory (for manipulation with GD Library)
		$createTempImg = imagecreatefromjpeg($imgSrc);

		// calculating the part of the image to use for thumbnail
		if ($width > $height) {
		  $y = 0;
		  $x = ($width - $height) / 2;
		  $smallestSide = $height;
		} else {
		  $x = 0;
		  $y = ($height - $width) / 2;
		  $smallestSide = $width;
		}

		// copying the part into thumbnail
		$thumb = imagecreatetruecolor(354,354);
		imagecopyresampled($thumb, $createTempImg, 0, 0, $x, $y, 354, 354, $smallestSide, $smallestSide);
		//final output
		// header('Content-type: image/jpeg');
		imagejpeg($thumb, $_SERVER['DOCUMENT_ROOT'].'/wewant1/upload/image_product/x354-'.$idSrcImg.'.jpg');

		//create img cho thumbsize = 200px
		$thumb = imagecreatetruecolor(200,200);
		imagecopyresampled($thumb, $createTempImg, 0, 0, $x, $y, 200, 200, $smallestSide, $smallestSide);
		imagejpeg($thumb, $_SERVER['DOCUMENT_ROOT'].'/wewant1/upload/image_product/x200-'.$idSrcImg.'.jpg');

		//xoa file TempImg khi da dung xong
		imagedestroy($createTempImg);
		
		return true;
	}
?>